var app = getApp();
Component({

  properties: {
        list: Array,
        params : Object,
        sort : Array,
        color : String,
        citylist : Array,
        listtype : Boolean,
        sortid : Number,
        sorttwo : Number,
        type : String,
        tab0name : String,
        goodstype : Array,
        tablist : Array,
        ordertype : Array,
        shopid : Number,
        shopsort : Number,
    },
    data : {
        isfixed : false,
        showselect : false,
        selecttype : 1,
        otype : 0,
        gtype : 0,
        cityid : 0,
        sorttwoid : 0,
    },
    options : {
        addGlobalClass : true,
    },
    ready : function(){
        this.setData({
           'tablist[0].name' : this.data.tab0name
        })
    },
    methods: {
        navigateto : function( e ){
            app.com.navigateto( e );
        },
        tabChange(e){
            var sortid = e.currentTarget.dataset.status;
            var i = e.currentTarget.dataset.i;
            this.setData({
                sortid : sortid*1,
                shopsort : this.data.shopid > 0 ? sortid : 0,
                'tablist[0].name' : this.data.params.topshs*1 == 0 ? this.data.params.goodbname+'分类' : this.data.tab0name,
                showsortid : 'sortid'+sortid,
                sorttwoid : 0,
            })
            var data = {
                'page.pdata.sortid' : this.data.shopid > 0 ? 0 : sortid,
                'page.pdata.shopsort' : this.data.shopid > 0 ? sortid : 0,
                'page.pdata.sorttwo' : 0,
            };
            this.triggerEvent('setList', data);
        },
        showselect(){
            this.setData({
                showselect : !this.data.showselect
            })
        },
        clearsearch(){
            var e = {
                detail : '',
            }
            this.searchfn(e);
        },
        searchfn(e){
            var data = {
                'page.pdata.search' : e.detail,
                'page.pdata.sortid' : 0,
                'page.pdata.shopsort' : 0,
                'page.pdata.sorttwo' : 0,
            };
            this.triggerEvent('setList', data);
        },
        sorder(e){
            var otype = e.currentTarget.dataset.type;
            var i = e.currentTarget.dataset.i;
            if(this.data.otype == otype) return false;
            this.setData({
                'tablist[1].name' : this.data.ordertype[i].name,
                showselect : false,
                otype : otype,
            })

            var data = {
                'page.pdata.otype' : otype,
            };
            this.triggerEvent('setList', data);
        },
        selectgood(e){
            var gtype = e.currentTarget.dataset.type;
            var i = e.currentTarget.dataset.i;
            if(this.data.gtype == gtype) return false;
            this.setData({
                'tablist[2].name' : this.data.goodstype[i].name,
                showselect : false,
                gtype : gtype,
            })

            var data = {
                'page.pdata.gtype' : gtype,
            };
            this.triggerEvent('setList', data);
        },
        scity(e){
            var cityid = e.currentTarget.dataset.type;
            var index = e.currentTarget.dataset.index;
            if(this.data.cityid == cityid) return false;
            this.setData({
                'tablist[0].name' : this.data.citylist[index].name,
                showselect : false,
                cityid : cityid,
            })

            var data = {
                'page.pdata.cityid' : cityid,
            };
            this.triggerEvent('setList', data);
        },
        ssorttwo(e){
            var sort = e.currentTarget.dataset.type;
            var index = e.currentTarget.dataset.i;
            var io = e.currentTarget.dataset.io;
            if(this.data.sorttwoid == sort) return false;
            this.setData({
                'tablist[0].name' : this.data.sort[io].down[index].name,
                showselect : false,
                sorttwoid : sort,
            })

            var data = {
                'page.pdata.sorttwo' : sort,
            };
            this.triggerEvent('setList', data);
        },
        showselectfn(e){
            if( e.currentTarget.dataset.type == 1 ){
                this.setData({
                    showselect : this.data.selecttype == 1 &&  this.data.showselect ? false : true,
                    selecttype  : 1,
                })
            }else if(e.currentTarget.dataset.type == 2){
                this.setData({
                    showselect : this.data.selecttype == 2 &&  this.data.showselect ? false : true,
                    selecttype  : 2,
                })
            }else if(e.currentTarget.dataset.type == 3){
                this.setData({
                    showselect : false,
                    listtype : !this.data.listtype,
                })
                this.triggerEvent('listtypefn', this.data.listtype);

            }else if(e.currentTarget.dataset.type == 4){
                this.setData({
                    showselect : this.data.selecttype == 4 &&  this.data.showselect ? false : true,
                    selecttype  : 4,
                })

            }
        },
        scroll(e){
            if(e.detail.scrollTop < -20 && !this.data.isfixed){
                this.setData({
                    isfixed : true,
                })
            }else if(e.detail.scrollTop >= -20){
                this.setData({
                    isfixed : false,
                })
            }
        },
    }

})